using UnityEngine;
using System.Collections;

public class MyGame : MonoBehaviour {

    public GameObject serverCube;

	// Use this for initialization
	void Start () {
        GameObject.Find("LifeText").active = false;
        GameObject.Find("CenterText").active = false;
        GameObject.Find("CenterText2").active = false;
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    void OnNetworkLoadedLevel()
    {
        Debug.LogError("Init My Game!!!!");
        if (serverCube != null)
        {
            if (Network.isServer)
            {
                Network.Instantiate(serverCube, new Vector3(0, 10, 0), transform.rotation, 0);
            }
            else
            {
                Network.Instantiate(serverCube, new Vector3(0, 10, 20), transform.rotation * Quaternion.Euler(0, 180, 0), 0);
            }
        }
    }

    void OnPlayerDisconnected(NetworkPlayer player)
    {
        // Removing player if Network is disconnected
        Debug.Log("Server destroying player");
        Network.RemoveRPCs(player, 0);
        Network.DestroyPlayerObjects(player);
    }


    void NotifyPlayerDeath()
    {
        GameOver();

    }


    // GameOver!!
    void GameOver()
    {
        GameObject text = GameObject.Find("CenterText");
        TextMesh mesh = (TextMesh)text.GetComponent("TextMesh");
        mesh.text = "GAME OVER";
        text = GameObject.Find("CenterText2");
        mesh = (TextMesh)text.GetComponent("TextMesh");
        mesh.text = "Press SPACE to exit...";
    }
}
